<template>
	<view class="inspectContent">
		<view class="upper">
			<commonNavBar title="专项检查" :showSearch="true"  @search="open" ></commonNavBar>
			<view class="step">
				<view v-for="(tabs,index) in stepList" :key="index" @click="stepActive(index)">
					<view :class="{'active': tabIndex == index}">
						{{ tabs.step }}
					</view>
				</view>
			</view> 
		</view>
		<view class="centre">
			<z-paging ref="paging"   autowire-list-name="inspectList"  	autowire-query-name="listData"   >
				<view class="li" v-for="(list, index) in inspectList" :key="index" @tap="addInspect(list.ID,list.IS_AUTHORITY, null,list.CHECK_ID,list.CHECK_STATUS)" >
					<view class="float">{{ list.PROCESS_NAME }}</view>
					<view class="h1">{{ index + 1 }}.{{ list.COMPANY_NAME }}</view>
					<!-- <view class="h2">业态:{{ list.RISK_LEVEL }}</view> -->
					<view class="h2">风险等级:{{ list.RISK_LEVEL }}</view>
					<view class="h2"  >许可证号:{{ list.LICENSE }}</view>
					<view class="h2"  >所属区局:{{ list.DEPT_QU_NAME }}</view>
					<view class="h2"  >监管单位:{{ list.DEPT_NAME }}</view>
					<view class="order" v-if="tabIndex === 0">
						<view class="dd"
							v-for="(order,index) in list.CHECK_LIST " :key="index"  :data-realy="order.CHECK_STATUS  == '1'"
							@tap.stop="addInspect(list.ID,list.IS_AUTHORITY, order.UNPLANNED_COMPANY_ID,order.CHECK_ID,order.CHECK_STATUS)"
							:class="( order.CHECK_STATUS  == '1' ? 'Active' : '')" >
							<view class="dd1">
								<text >{{ order.CHECK_END_DATE}}前</text>
								<text  v-text="order.CHECK_STATUS  == '1' ? '已检查':'未检查'"></text>
							</view> 
						</view> 
					</view>  
					<view class="h2" v-if="tabIndex === 1">检查日期:{{ list.CHECK_TIME }}</view> 
					<view class="h2" v-if="tabIndex === 1">处理结果:{{ list.PROCESS_RESULTS_TEXT }}</view> 
				</view>
			</z-paging>
		<CommonSearchCompontVue  @seacharResult="seacharResult" :showTime="tabIndex == 1" :tabIndex.sync="tabIndex" :showProcessResults="tabIndex == 1"
		 :showSearchCompont="showSearchCompont"  ></CommonSearchCompontVue>
		</view>
		<view class="fixed">当前已搜索到{{ total }}条数据</view>
	</view>
</template>

<script>
	import CommonSearchCompontVue from '../../components/CommonSearchCompont.vue'
	 import commonNavBar from '@/components/CommonNavBar.vue';
	 export default {
		components:{
			commonNavBar,
			CommonSearchCompontVue
		},
		data() {
			return { 
				stepList: [{
					step: '专项检查',
					active: true
				}, {
					step: '检查结果',
					active: false
				}],  
				tabIndex:0,
				showSearchCompont:false,
				inspectList: [], 
				total: 0,
				searchParams:{
					companyName: '', //企业名称
					firstType: '', //一级业态
					twoType: '', //二级业态
					companyIndex:0, // 企业环节
					companyLevel:'',//安全等级
					inspectStatus:'', // 检查情况
					companyProcess:'', // 企业环节
					supervisePerson:'', // 监管人
					existPeriphery:'', // 是否校园周边
					existWholesaleAgricultura:'', // 是否农产品批发
					existEx:'', // 是否异常主体
					onlyPrePackaging:'', // 仅售预包装食品
					haveSpecialFood:'', // 是否有特殊食堂
					address:'', // 企业地址
					startTime :'',
					endTime:'',
					pageNum:1,
					pageSize:10,
				}
			}
		},
		filters:{
			processResultsFilter(value){
				if(value = '1'){
					return '通过检查';
				} else if(value = '2'){
					return '责令整改';
				} else if(value = '3'){
					return '调查处理';
				} else if(value = '4'){
					return '立案查处';
				} else if(value = '5'){
					return '食品生产经营者立即停止食品生产经营活动';
				}
			}
		}, 
		onReady() {
			this.$refs.paging.reload();
		},
		methods: {
			open() { 
				this.showSearchCompont = true
			}, 
			seacharResult(e){
				//检索条件点击确定或者删除的时候在执行
				this.showSearchCompont =  false;
				if(e.search){ 
					this.searchParams = e;
					this.$refs.paging.reload();
				}
			},
			goBack() {
				uni.navigateBack();
			},
			async listData(pageNo, pageSize,reload) { 
				this.searchParams.pageNum = pageNo;
				this.searchParams.pageSize= pageSize;
				this.searchParams.type = this.tabIndex;
				try { 
					const res = await uni.$api.getSpecialCheckList(this.searchParams); 
					this.total = res.data.data.total ;
					this.$refs.paging.completeByKey(res.data.data.records,this.tabIndex);
				}  catch (error) { 
					 this.$refs.paging.complete(false);
				}
				
			}, 
			stepActive(index) {
				this.tabIndex = index;
				this.$refs.paging.reload(); 
			}, 
			/**
			 * @param {Object} checkId 检查单id
			 * @param {Object} status 状态 
			 */
			addInspect(companyId,isAuthority,unplannedCompanyId,checkId,status) { 
				const  that = this;
				if(status == '1' ){
					//查看结果
					uni.navigateTo({
						url: '/pages/inspect/resultActive?id=' + checkId 
					})
				} else { 
					//进行检查
					if(isAuthority != '1'){
						//没有权限操作
						uni.showToast({
							icon:'error',
							title: '无操作权限',
							duration: 4000
						})
						return;
					}
					uni.navigateTo({
						url: '/pages/specialInspect/specialCheck?unplannedCompanyId=' + unplannedCompanyId + "&companyId="+companyId + "&detail="+(isAuthority != '1')
						,events: {
							// 为指定事件添加一个监听器，获取被打开页面传送到当前页面的数据
							reloadList: function(data) {
							   that.$refs.paging.reload();
							} 
						}
					})
				}
			
			} ,
			close() {
				this.$refs.popup.close()
			}, 
			cancellation() {
				this.close()
			} 
		},
		watch: {
			
		},
	}
</script>

<style lang="scss">
	.inspectContent {
		background: #F9F9F9;
		height: calc(100vh - 195rpx);

		.upper {
			position: fixed;
			z-index: 1;
			top: 0;
			left: 0;
			width: 100%; 
			
			.step {
				display: flex;
				justify-content: space-around;
				height: 80rpx;
				line-height: 80rpx;
				background: #F9F9F9;

				view {
					position: relative;
					font-size: 25rpx;
					font-family: PingFangSC-Regular, PingFang SC;
					font-weight: 400;
					color: #999999;

					&.active {
						color: #0552A9;

						&::before {
							display: block;
							content: "";
							position: absolute;
							left: 50%;
							bottom: 0%;
							transform: translate(-50%, 0%);
							width: 100rpx;
							height: 5rpx;
							background: #0552A9;
						}
					}
				}
			}
		}

		.centre {
			margin: 195rpx 0 0 0;
			padding: 0 17.5rpx;
			height: calc(100vh - 280rpx);
			overflow-x: hidden;
			
			.z-paging-content-fixed {
				padding: 195rpx 0 0 0;
			}

			.li {
				background: linear-gradient(180deg, #FFFFFF 0%, #FFFFFF 100%);
				box-shadow: 0rpx 8rpx 15rpx 0rpx rgba(0, 0, 0, 0.05);
				border-radius: 15rpx;
				padding: 30rpx 30rpx 15rpx 28rpx;
				position: relative;
				margin: 13rpx 20rpx 0;

				.float {
					position: absolute;
					top: 0;
					right: 0;
					// width: 97rpx;
					padding: 0 10rpx;
					height: 46rpx;
					line-height: 46rpx;
					background: linear-gradient(180deg, #5DA1FF 0%, #0054C9 100%);
					border-radius: 0rpx 11rpx 0rpx 11rpx;
					font-size: 18rpx;
					font-family: PingFangSC-Medium, PingFang SC;
					font-weight: 500;
					color: #FFFFFF;
					text-align: center;
				}

				.h1 {
					font-size: 24rpx;
					font-family: PingFangSC-Medium, PingFang SC;
					font-weight: 500;
					color: #333333;
					line-height: 1;
					margin: 0 0 14rpx 0;
				}

				.h2 {
					font-size: 19rpx;
					font-family: PingFangSC-Regular, PingFang SC;
					font-weight: 400;
					color: #666666;
					line-height: 1;
					margin: 12rpx auto;
				}

				.order {
					margin: 24rpx auto 0; 
					white-space: nowrap;
					overflow-x: auto; 
					
					.dd {
						width: 120rpx;
						height: 55rpx;
						border-radius: 9rpx;
						border: 1rpx solid #979797;
						font-size: 16rpx;
						font-family: PingFangSC-Medium, PingFang SC;
						font-weight: 700;
						color: #A1A1A1; 
						position: relative;
						text-indent: -10rpx;
						display: inline-block;
						text-align: center; 
						
						.dd1{ 
							display: flex;
							flex-direction: column;
							align-items: center;
							justify-content: center; 
							height: 55rpx;
						}

						 
	
						.triangle {
							width: 0;
							height: 0;
							border-top: 8rpx solid transparent;
							border-bottom: 8rpx solid transparent;
							border-left: 10rpx solid #A1A1A1;
							position: absolute;
							top: 50%;
							right: 4rpx;
							transform: translate(-50%, -50%);
						}

						&+.dd {
							margin: 0 0 0 12rpx;
						}

						&.Active {
							border: 1px solid #F9A240;
							background: #F9A240;
							color: #fff;
							
							.triangle {
								border-left: 10rpx solid #fff;
							}
						}
						

						&.Danger {
							border: 1px solid #F95E5A;
							background: #F95E5A;
							color: #fff;
							
							.triangle {
								border-left: 10rpx solid #fff;
							}
						}
						
						&.special { 
							border: 1px solid #00BE8C;
							background: #00BE8C;
							color: #fff;
							
							.triangle {
								border-left: 10rpx solid #fff;
							}
						}
					}
				}
			}
		}

		.fixed {  
			position: fixed;
			left: 50%;
			bottom: 26rpx;
			transform: translate(-50%, 0);
			width: 100%;
			text-align: center;
			font-size: 18rpx;
			font-family: PingFangSC-Regular, PingFang SC;
			font-weight: 400;
			color: #A7A7A7;
		}

		.popupContent {
			background: #FFFFFF;
			border-radius: 20rpx 20rpx 0 0;

			.uni-datetime-picker {
				width: 100%;
			}

			.title {
				width: 100%;
				height: 80rpx;
				line-height: 80rpx;
				background: url('../../static/img/popupTitle.png') no-repeat center center;
				background-size: cover;
				font-size: 25rpx;
				font-family: PingFangSC-Medium, PingFang SC;
				font-weight: 500;
				color: #FFFFFF;
				text-indent: 45rpx;
			}

			.ul {

				.li {
					padding: 0 45rpx;
					margin: 0 auto;
					display: flex;
					justify-content: space-between;
					align-items: center;
					height: 68rpx;
					line-height: 68rpx;
					border-bottom: 1px solid #d6d6d6;
						
					.left {
						font-size: 21rpx;
						font-family: PingFangSC-Regular, PingFang SC;
						font-weight: 400;
						color: #333333;
					}
						
					.right {
						
						input {
							font-size: 21rpx;
							font-family: PingFangSC-Regular, PingFang SC;
							font-weight: 400;
							color: #999999;
							width: 460rpx;
							text-indent: 20rpx;
						}
						
						.placeholder-class {
							color: #999999;
						}
						
						.uni-stat__select {
							width: 460rpx;

							/deep/.uni-select {
								border: none;
							}
						}
						
						.uni-date {
							width: 460rpx;
							
							/deep/.uni-date-editor--x {
								border: none;
							}
						}
					}
					
					&:nth-child(odd) {
						background: #F9F9F9;
					}
					
					&:last-child {
						border-bottom: none;
					}
				}
				
				.li:last-child {
					/deep/.uni-select__selector {
						top: initial;
					}
					
					/deep/.uni-popper__arrow {
						display: none;
					}
				}
			}
			
			.button {
				margin: 58rpx auto 0;
				padding: 0 95rpx 24rpx 95rpx;
				display: flex;
				
				button {
					width: 269rpx;
					height: 55rpx;
					line-height: 55rpx;
					background: #0552A9;
					border-radius: 10rpx;
					font-size: 20rpx;
					font-family: PingFangSC-Regular, PingFang SC;
					font-weight: 400;
				
					&.determine {
						color: #fff;
					}
					
					&.cancellation {
						background: none;
						border: 1rpx solid #979797;
						color: #979797;
					}
				}
			}
		}
	}
	.navigator-check{
		position: absolute;
		width: 100rpx;
		height: 100rpx;
		z-index: 9;
		right: 0px;
		bottom: 0px;
		border-radius: 0rpx 0rpx 15rpx 0rpx;
	}
</style>
